package com.pacifictextiles.qc.inspection.server.model.test;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.pacifictextiles.qc.inspection.server.model.dao.impl.WasteDAOImpl;
import com.pacifictextiles.qc.inspection.server.model.vo.Waste;

/**
 * Servlet implementation class AddWaste
 */
public class AddWaste extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddWaste() {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// 设置数据编码
		response.setContentType("text/html; charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		
		// 获取参数
		Waste waste = new Waste();
		waste.setBeginPosition(Float.parseFloat(request.getParameter("beginPosition")));
		waste.setIndexInRoll(Integer.parseInt((request.getParameter("indexInRoll"))));
		waste.setDefectCode(Integer.parseInt(request.getParameter("defectCode")));
		waste.setEndPosition(Float.parseFloat(request.getParameter("endPosition")));
		waste.setRollNo(request.getParameter("rollNo"));
		waste.setWasteLength(Float.parseFloat(request.getParameter("wasteLength")));
		
		// 执行数据库操作
		WasteDAOImpl wdi = new WasteDAOImpl();
		try {
			if (wdi.addWaste(waste)) {
				System.out.println("Insert waste success!");
			} else {
				System.out.println("Insert waste faild");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
